package xperiment.metaphor.model.resource;


public class TextResource implements Comparable<TextResource> {

    private String code;
	
    private String value;

	private xperiment.metaphor.model.resource.Locale locale;

	public TextResource() {
		
	}
	
	public TextResource(String value) {
		this(java.util.Locale.getDefault(), value);
	}
	
	public TextResource(java.util.Locale locale, String value) {
		this.locale = new xperiment.metaphor.model.resource.Locale(locale);
		this.value = value;
	}

	public TextResource(String language, String country, String value) {
		this.locale = new xperiment.metaphor.model.resource.Locale(language, country);
		this.value = value;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public xperiment.metaphor.model.resource.Locale getLocale() {
		return locale;
	}

	public void setLocale(xperiment.metaphor.model.resource.Locale locale) {
		this.locale = locale;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final TextResource other = (TextResource) obj;
		if (this.value != other.value && (this.value == null || !this.value.equals(other.value))) {
			return false;
		}
		return true;
	}

	@Override
	public int hashCode() {
		int hash = 7;
		hash = 41 * hash + (this.value != null ? this.value.hashCode() : 0);
		return hash;
	}

	
	@Override
	public int compareTo(TextResource o) {
		if (o == null) {
			return -1;
		}
		
		if (o.getValue() == null && this.value == null) {
			return 0;
		}
		
		if (this.value != null) {
			return this.value.compareTo(o.getValue());
		}
		return o.getValue().compareTo(this.value);
	}
}

